package study.dq.jms.p2p;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author dongqun
 * @version 1.0
 * @description 类的功能描述
 * @date 2019/10/18 18:45
 */
public class TestProducter {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(10);
        Producter producter = new Producter("admin", "admin", "tcp://127.0.0.1:61616");
        service.submit(new ProducerTask(producter));
        service.submit(new ProducerTask(producter));
        service.submit(new ProducerTask(producter));
        service.submit(new ProducerTask(producter));
        service.submit(new ProducerTask(producter));
    }

    private static class ProducerTask implements Runnable {
        private Producter producter;

        public ProducerTask(Producter producter) {
            this.producter = producter;
        }

        @Override
        public void run() {
            while (true) {
                try {
                    producter.sendMessage("QUEUE_TEST_1");
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
